<?php

	##################################################
	#
	# Copyright (c) 2004-2006 OIC Group, Inc.
	# Written and Designed by James Hunt
	#
	# This file is part of Exponent
	#
	# Exponent is free software; you can redistribute
	# it and/or modify it under the terms of the GNU
	# General Public License as published by the Free
	# Software Foundation; either version 2 of the
	# License, or (at your option) any later version.
	#
	# GPL: http://www.gnu.org/licenses/gpl.txt
	#
	##################################################

    /**
    * Change logs
    * Aug 9, 2012 - trungdt - Add support : ID can be absent, auto select first record belongs to  SRC
    */
    
	if (!defined('EXPONENT')) exit('');

	$textitem = null;
	if (isset($_GET['id'])) {
		$textitem = $db->selectObject('textitem','id=' . intval($_GET['id']));
	}
    else
    {
        $location = serialize($loc);
        $textitem = $db->selectObject('textitem',"location_data='" . $location . "'");
        if (!$textitem)
        {
            $textitem=null;
        }
    }

	if ($textitem != null) {
		$loc = unserialize($textitem->location_data);
	}

	if (exponent_permissions_check('edit',$loc)) {

		$form = textitem::form($textitem);
		$form->location($loc);
		$form->meta('action','save');

		$template = new template('textmodule','_form_edit',$loc);
		$template->assign('is_edit',(isset($textitem->id)? 1 : 0));
		$template->assign('form_html',$form->toHTML());
		$template->output();
        exponent_sessions_set("AB_THEME_TOP_CONTAINER_SRC","top_loginmodule_".LANG);
    exponent_sessions_set("AB_THEME_TOP_CONTAINER_TYPE","textmodule");
	} else {
		echo exponent_http_error(403);
	}

?>
